home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / doc / il2doc.awk < prev    next >
Encoding:
AWK Script  |  1996-09-27  |  4.1 KB  |  149 lines

  1. BEGIN {
  2.     LIMIT="`"
  3.     FS=LIMIT
  4.     parts="@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  5.     last_tag=" "
  6.     part_no=0
  7.     ind=""
  8.     low_ind=""
  9.     line=""
  10.     entry=""
  11.     entry_lim=4
  12.     no_entry=0
  13.     IND_FORMAT="l r"
  14.     #{{{}}}
  15. #    {{{  init lowercase field
  16.     lowercase["A"]="a"; lowercase["B"]="b"; lowercase["C"]="c"
  17.     lowercase["D"]="d"; lowercase["E"]="e"; lowercase["F"]="f"
  18.     lowercase["G"]="g"; lowercase["H"]="h"; lowercase["I"]="i"
  19.     lowercase["J"]="j"; lowercase["K"]="k"; lowercase["L"]="l"
  20.     lowercase["M"]="m"; lowercase["N"]="n"; lowercase["O"]="o"
  21.     lowercase["P"]="p"; lowercase["Q"]="q"; lowercase["R"]="r"
  22.     lowercase["S"]="s"; lowercase["T"]="t"; lowercase["U"]="u"
  23.     lowercase["V"]="v"; lowercase["W"]="w"; lowercase["X"]="x"
  24.     lowercase["Y"]="y"; lowercase["Z"]="z"
  25. #    }}}
  26. #    {{{  print auto-gen tag
  27.     printf(".\\%c generated automatically, containing the index data\n",34)
  28. #    }}}
  29. #    {{{  print header of table
  30.     printf(".bp\n")
  31.     printf(".nH 1 Index\n")
  32.     printf(".LP\n")
  33.     printf(".if \\n(gR .2C\n")
  34.     printf("There are 3 types of indices:\n")
  35.     printf(".TS\n")
  36.     printf("center tab(" LIMIT ");\n")
  37.     printf("l l.\n")
  38.     printf(" \\fBline\\fP" LIMIT "marks a definition.\n")
  39.     printf(" \\fIline\\fP" LIMIT "marks an example.\n")
  40.     printf(" line" LIMIT "marks a normal reference.\n")
  41.     printf(".TE\n")
  42.     printf(".if \\n(gR .SM\n")
  43.     printf(".TS\n")
  44.     printf("center tab(" LIMIT ");\n")
  45.     printf("%s.\n",IND_FORMAT)
  46. #    }}}
  47. }
  48. {
  49. #   {{{  handle index
  50.    if (substr($1,1,1)==" ")
  51.        in_index=substr($1,2)
  52.    else
  53.        in_index=$1
  54. #   {{{  set low_in_index to tolower(in_index)
  55.    low_in_index=""
  56.    for (i=0; i<length(in_index);) if ((l=lowercase[c=substr(in_index,++i,1)])=="") { low_in_index=low_in_index c } else { low_in_index=low_in_index l }
  57. #   }}}
  58.    if (in_index!=ind) {
  59.       if (low_ind==low_in_index) {
  60. #          {{{  use upper case entry
  61.           ind=low_in_index
  62.           low_ind=low_in_index
  63. #          }}}
  64.       } else {
  65. #          {{{  get tag
  66.           tag=substr(low_in_index,1,1)
  67.           part_no=0
  68.           for (;part_no<=length(parts)&&tag!=substr(parts,part_no,1);part_no++);
  69. #          }}}
  70. #          {{{  maybe print old entry
  71.           if (entry!="") {
  72.               if (substr(ind,1,1)==".") printf("\&")
  73.               if (substr(ind,1,1)=="=") printf("\&")
  74.               printf("%s" LIMIT "%s\n",substr(ind,1,length(ind)-1),entry)
  75.           }
  76. #          }}}
  77. #          {{{  maybe print header
  78.           if (tag!=last_tag || entry=="") {
  79.               printf("\n")
  80.               if (part_no<=length(parts)) printf("\\fB%s\\fP:\n",tag)
  81.           }
  82. #          }}}
  83. #          {{{  start new entry
  84.           entry=""
  85.           no_entry=0
  86.           last_tag=tag
  87.           ind=in_index
  88.           low_ind=low_in_index
  89.           line=""
  90. #          }}}
  91.       }
  92.    
  93.    }
  94. #   }}}
  95. #   {{{  handle line
  96.    if ($2!=line) {
  97. #       {{{  maybe gen whitespace between numbers
  98.        if (no_entry!=entry_lim) {
  99.            if (no_entry!=0) entry=entry " "
  100.            no_entry++
  101.        } else {
  102.            entry=entry "\n" LIMIT
  103.            no_entry=1
  104.        }
  105. #       }}}
  106. #       {{{  get offset of number
  107.        for (j=0;;)
  108.            if (substr($2,j,1)==" ")
  109.                j++
  110.            else
  111.                break
  112.        for (;;)
  113.            if (substr($2,j,1)=="0")
  114.                j++
  115.            else
  116.                break
  117. #       }}}
  118. #       {{{  maybe change font
  119.        if (substr($2,11,1)=="d")
  120.            entry=entry "\\fB"
  121.        else if (substr($2,11,1)=="x")
  122.            entry=entry "\\fI"
  123. #       }}}
  124.        line_digit=substr($2,j,11-j)
  125.        while (length(line_digit) && substr(line_digit,1,1)=="0")
  126.           line_digit=substr(line_digit,2)
  127.        entry=entry line_digit
  128. #       {{{  maybe change font
  129.        if (substr($2,11,1)!="i")
  130.            entry=entry "\\fP"
  131. #       }}}
  132.    }
  133. #   }}}
  134.    line=$2
  135. }
  136. END {
  137.     if (entry=="") {
  138.         printf("\n")
  139.     } else {
  140. #        {{{  print last entry
  141.         if (substr(ind,1,1)==".") printf("\&")
  142.         if (substr(ind,1,1)=="=") printf("\&")
  143.         printf("%s" LIMIT "%s\n",substr(ind,1,length(ind)-1),entry)
  144. #        }}}
  145.     }
  146.     printf(".TE\n")
  147.     printf(".if \\n(gR .LG\n")
  148. }
  149.